<template>
  <div class="mod-shop-notice">
    <avue-crud
      ref="searchRef"
      v-model:search="search"
      :page="page"
      :data="dataList"
      :table-loading="dataListLoading"
      :option="tableOption"
      @search-change="onSearch"
      @on-load="getDataList"
      @refresh-change="refreshChange"
    >
      <template #menu-left>
        <el-button
          v-if="isAuth('shop:notice:save')"
          plain
          type="success"
          icon="el-icon-upload"
          @click="handleImport()"
        >
          导入
        </el-button>
        <el-button
          v-if="isAuth('shop:notice:save')"
          plain
          type="warning"
          icon="el-icon-download"
          @click="handleOut()"
        >
          导出
        </el-button>
      </template>
    </avue-crud>

    <upload-modal ref="uploadModalRef" @refresh-data-list="refreshChange" />
  </div>
</template>

<script setup>
import { isAuth } from "@/utils";
import { ElMessage, ElMessageBox } from "element-plus";
import { tableOption } from "@/crud/orderUtils/orderUtil.js";
import uploadModal from "./upload-modal.vue";
import { saveAs } from "file-saver";
import { download } from "@/utils/http.js";

const dataList = ref([]);
const page = reactive({
  total: 0, // 总页数
  currentPage: 1, // 当前页数
  pageSize: 10, // 每页显示多少条
});

const dataListLoading = ref(false);
const addOrUpdateVisible = ref(false);

const getDataList = (pageParam, params, done) => {
  dataListLoading.value = true;
  http({
    url: http.adornUrl("/admin/ghOrderCollect/initList"),
    method: "get",
    params: http.adornParams(
      Object.assign(
        {
          current: pageParam == null ? page.currentPage : pageParam.currentPage,
          size: pageParam == null ? page.pageSize : pageParam.pageSize,
        },
        params
      )
    ),
  }).then(({ data }) => {
    dataList.value = data.records;
    page.total = data.total;
    dataListLoading.value = false;
    if (done) done();
  });
};
const search = ref({});

// 导出数据
const handleOut = () => {
  let params = search.value;
  let fileName = "订单汇总_" + new Date().getTime() + ".xlsx";
  download("/admin/ghOrderCollect/exportExcel", params, fileName);
};

const uploadModalRef = ref(null);

const handleImport = () => {
  uploadModalRef.value?.init();
};



/**
 * 刷新回调
 */
const refreshChange = () => {
  getDataList(page);
};

const onSearch = (params, done) => {
  getDataList(page, params, done);
};
</script>

<style lang="scss" scoped></style>
